#!/usr/bin/env dash
#
# This file is part of OpenMediaVault.
#
# @license   http://www.gnu.org/licenses/gpl.html GPL Version 3
# @author    Volker Theile <volker.theile@openmediavault.org>
# @copyright Copyright (c) 2009-2023 Volker Theile
#
# OpenMediaVault is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# OpenMediaVault is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenMediaVault. If not, see <http://www.gnu.org/licenses/>.
#
# NOTE:
# If the machine does not run 24/7 it might happen that cron-apt is not
# executed. Because anacron does not execute cron jobs defined in /etc/cron.d
# (where the default cron-apt cron job file is located) this script ensures
# that cron-apt is executed at least once a day.
MAILTO=""

export LANG=C

. /etc/default/openmediavault
. /usr/share/openmediavault/scripts/helper-functions

OMV_CRON_APT_ENABLED=${OMV_CRON_APT_ENABLED:-"yes"}

# Execute cron-apt to check for new updates and automatically download/install
# security updates.
if omv_checkyesno "${OMV_CRON_APT_ENABLED}"; then
  which cron-apt >/dev/null 2>&1 && cron-apt
fi

# Send an email when a reboot is required.
if [ -e "/run/reboot-required" ]; then
  msg="A reboot of the system is required to complete a package upgrade."
  omv_syslog_info ${msg}
  echo ${msg} | mail -E -s "Reboot required" root
fi
